/**
 * 
 * 角色 Miva
 * 实例化时需要,传入参数
 * @param options    角色初始数据
 * @param name       角色名
 * @param 
 */
class Miva extends Role {

    public constructor(name) {
        super();
        this.role_name.text = name;
        this.role_png.texture = RES.getRes("mage_skin_10_png");
        Utils.anchorCenter(this.role_png);
        this.role_png.scaleX = 2;
        this.role_png.scaleY = 2;
        this.stand();
        this.walk();
    }

    public stand() {
        const standTimer = new egret.Timer(1000 / 3);
        let num = 10;
        standTimer.addEventListener(egret.TimerEvent.TIMER, () => {
            if (this.nowState != 1) return;
            num++;
            if (num > 13) num = 10;
            this.role_png.texture = RES.getRes(`mage_skin_${num}_png`);
            Utils.anchorCenter(this.role_png);
        }, this);

        standTimer.start();
    }

    public walk() {
        const walkTimer = new egret.Timer(1000 / 7);
        /** 0~9 */
        let num = 0;
        walkTimer.addEventListener(egret.TimerEvent.TIMER, () => {
            if (this.nowState != 2) return;
            if (!this.canWalk) return;
            num++;
            if (num > 9) num = 0;
            this.role_png.texture = RES.getRes(`mage_skin_${num}_png`);
            Utils.anchorCenter(this.role_png);
        }, this);

        walkTimer.start();
    }

    /** 109~113 */
    public attack() {
        if( this.canAttack == false) return;
        const oldState = this.nowState;
        this.nowState = 3;
        this.canWalk = false;
        this.canAttack = false;
        const timer = new egret.Timer(1000 / 10, 113 - 109);
        let num = 109;
        timer.addEventListener(egret.TimerEvent.TIMER, () => {
            num++;
            this.role_png.texture = RES.getRes(`mage_skin_${num}_png`);
            Utils.anchorCenter(this.role_png);
        }, this);
        timer.addEventListener(egret.TimerEvent.TIMER_COMPLETE, () => {
            this.nowState = oldState;
            this.canWalk = true;
            this.canAttack = true;
        }, this)

        timer.start();
    }

}